package ar.com.cooker.services.uow.recipe;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ar.com.cooker.dao.RecipeDao;
import ar.com.cooker.model.Recipe;
import ar.com.cooker.services.pojo.RecipePojo;
import ar.com.cooker.services.uow.GetAllUOW;
import ar.com.cooker.services.util.ConvertBOtoPojo;

@Component(value= "getAllRecipeUOW")
public class GetAllRecipeUOW implements GetAllUOW<RecipePojo> {

	@Autowired
	private RecipeDao recipeDao;
	
	@Override
	public RecipePojo[] execute() {
		
		RecipePojo[] recipePojos = null;
		int cant = 0;
		List<Recipe> recipes = getRecipeDao().findAll();
		recipePojos = new RecipePojo[recipes.size()];
		for(Recipe r : recipes){
			recipePojos[cant] = ConvertBOtoPojo.getRecipePojoToRecipe(r);
			cant ++;
		}
		return recipePojos;
	}

	public void setRecipeDao(RecipeDao recipeDao) {
		this.recipeDao = recipeDao;
	}

	public RecipeDao getRecipeDao() {
		return recipeDao;
	}



}
